/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Army.task;

import Army.BuildingAndUnit;
import java.awt.Point;

/**
 *
 * @author Huy
 */
public class TaskLocate extends Task {

	protected Point targetPosision;
	protected int wages = 0;

	public TaskLocate(BuildingAndUnit source, Point targetPosision) {
		this.source = source;
		this.targetPosision = targetPosision;
		taskName = "Locate";
	}

	@Override
	public Point getPosisition() {
		return targetPosision;
	}

	@Override
	public boolean execute() {
		if (source.getPosition().distance(targetPosision) < source.getSpeed() * 3) {
			//	isDone = true;
			if (wages++ > 50) {
				source.setRotation(Math.random() * Math.PI * 2);
				wages = 0;
			}
		} else {
			source.run();
			source.setTarget(targetPosision);
		}
		return isDone;

	}
}
